import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/components/education/custom_new_title_chart_page.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/data/entities/double_control/get_task_record_by_unit_id_entity.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/hazard_investigation/annual_hazard_plan/annual_hazard_plan_detail/annual_hazard_planinfo/annual_hazard_plan_task/annual_hazard_plan_task_controller.dart';

///单元-》任务
class AnnualHazardPlanTaskPage extends StatelessWidget {
  AnnualHazardPlanTaskPage({super.key});

  final controller = Get.put(AnnualHazardPlanTaskController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            key: controller.riskRightScaffoldKey,
            backgroundColor: AppColors.bg_color_grey,
            appBar: CustomAppBar(
              titleText: '任务',
            ),
            body: Container(
              color: AppColors.bg_color_grey,
              padding: EdgeInsets.only(top: 12.w, right: 14.w, left: 14.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    controller.riskUnitName,
                    style: TextStyle(
                      fontSize: 16.sp,
                      color: const Color(0xFFA5A6B5),
                      overflow: TextOverflow.ellipsis,
                      fontWeight: FontWeight.w500,
                    ),
                  ),
                  Expanded(
                      child: CustomEasyRefreshList<GetTaskRecordByUnitIdEntity>(
                    key: controller.globalKey,
                    enableLoad: false,
                    dataLoad: controller.getTaskRecordByUnitId,
                    itemBuilder: (item, index) {
                      return CustomNewTitleChartPage(child: _rowData(item.riskMeasureDesc ?? '', '', alignment: Alignment.centerLeft));
                    },
                  )),
                ],
              ),
            ),
          );
        });
  }

  Widget _rowData(String name, String value, {Alignment alignment = Alignment.centerLeft}) {
    return Row(
      children: [
        Text(
          name,
          style: TextStyle(
            color: const Color(0xFFA5A6B5),
            fontWeight: FontWeight.w400,
            fontSize: 13.sp,
          ),
        ),
        Expanded(
          child: Align(
            alignment: alignment,
            child: Text(
              value,
              style: TextStyle(
                color: const Color(0xFF495061),
                fontSize: 12.sp,
                fontWeight: FontWeight.w400,
              ),
            ),
          ),
        )
      ],
    );
  }
}
